package com.sjk.flink.schema;

import com.fasterxml.jackson.databind.JsonNode;
import networknt.schema.*;
import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.Set;

public class GroovyKeyword extends AbstractKeyword {
    private static final Logger logger = LoggerFactory.getLogger(GroovyKeyword.class);

    public GroovyKeyword() {
        super("groovy");
    }

    @Override
    public AbstractJsonValidator newValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) throws JsonSchemaException, Exception {
        // you can read validator config here
        String config = schemaNode.asText();
        return new AbstractJsonValidator() {
            @Override
            public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String at) {
                // you can do validate here
                logger.info("config:{} path:{} node:{}", config, at, node);
                //this.getValue();
                System.out.println("config     "+config);
                System.out.println("at     "+at);
                System.out.println("at     "+node);
                return Collections.emptySet();
            }
        };
    }
}
